﻿@page

@using System.Globalization
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using Microsoft.Extensions.Localization
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Button
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Card
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Tab
@using Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.Codemirror
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.TuiEditor
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.Uppy
@using Volo.CmsKit.Admin.Web.Layouts
@using Volo.CmsKit.Admin.Web.Pages
@using Volo.CmsKit.Admin.Web.Menus
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.Slugify
@using Volo.Abp.Data
@using Volo.Abp.Localization
@using Volo.Abp.ObjectExtending
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Pages
@inject IStringLocalizerFactory StringLocalizerFactory

@inherits CmsKitAdminPageBase

@model Volo.CmsKit.Admin.Web.Pages.CmsKit.Pages.CreateModel

@{
    PageLayout.Content.Title = L["Pages"].Value;
    PageLayout.Content.BreadCrumb.Add(L["Menu:CMS"].Value);
    PageLayout.Content.MenuItemName = CmsKitAdminMenus.Pages.PagesMenu;
}

@section scripts {
<abp-script-bundle>
    <abp-script type="typeof(TuiEditorScriptContributor)" />
    <abp-script type="typeof(UppyScriptContributor)" />
    <abp-script type="typeof(SlugifyScriptContributor)" />
    <abp-script type="typeof(CodemirrorScriptContributor)"/>
    <abp-script src="/libs/codemirror/mode/css/css.js"/>
    <abp-script src="/libs/codemirror/mode/javascript/javascript.js"/>
    <abp-script src="/client-proxies/cms-kit-common-proxy.js"/>
    <abp-script src="/client-proxies/cms-kit-admin-proxy.js"/>
    <abp-script src="/Pages/CmsKit/Pages/create.js" />
    <abp-script src="/Pages/CmsKit/Contents/addWidgetModal.js" />
</abp-script-bundle>
}

@section styles {
<abp-style-bundle>
    <abp-style type="typeof(TuiEditorStyleContributor)" />
    <abp-style type="typeof(CodemirrorStyleContributor)" />
    <abp-style src="/Pages/CmsKit/Pages/create.css"/>
</abp-style-bundle>
}

<abp-card>
    <abp-card-header title="@L["New"].Value"></abp-card-header>
    <abp-card-body>
        <form asp-page="/CmsKit/Pages/Create" id="form-page-create">
            <abp-input asp-for="@Model.ViewModel.Title" />

            <abp-input asp-for="ViewModel.Slug" label-tooltip-icon="fa fa-info-circle" label-tooltip="@L["PageSlugInformation"]" />

            <abp-select id="Layout" asp-for="ViewModel.LayoutName" asp-items="@LayoutConstants.GetLayoutsSelectList()" label="@L["SelectLayout"]"></abp-select>

            <abp-input asp-for="@Model.ViewModel.Status" />

            <abp-input asp-for="@Model.ViewModel.Content" />

            <abp-tabs tab-style="Tab">

                <abp-tab title="@L["Content"]">
                    <div class="content-editor cms-kit-editor"
                         id="ContentEditor"
                         data-input-id="@Html.IdFor(x => x.ViewModel.Content)"
                         data-language="@(CultureInfo.CurrentUICulture.TwoLetterISOLanguageName)">
                    </div>
                </abp-tab>

                <abp-tab title="@L["Script"]">
                    <abp-input asp-for="ViewModel.Script" suppress-label="true" />
                </abp-tab>

                <abp-tab title="@L["Style"]">
                    <abp-input asp-for="ViewModel.Style"  suppress-label="true"/>
                </abp-tab>

            </abp-tabs>
            
            @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties<CreateModel.CreatePageViewModel>())
            {
                if (!propertyInfo.Name.EndsWith("_Text"))
                {
                    if (propertyInfo.IsEnum() || !propertyInfo.Lookup.Url.IsNullOrEmpty())
                    {
                        if (propertyInfo.IsEnum())
                        {
                            Model.ViewModel.ExtraProperties.ToEnum(propertyInfo.Name, propertyInfo.Type);
                        }
                        <abp-select asp-for="ViewModel.ExtraProperties[propertyInfo.Name]"
                                    enum-type="@propertyInfo.IsEnum() ? propertyInfo.Type : null"
                                    label="@propertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)"
                                    autocomplete-api-url="@propertyInfo.Lookup.Url"
                                    autocomplete-selected-item-name="@Model.ViewModel.GetProperty(propertyInfo.Name+"_Text")"
                                    autocomplete-selected-item-value="@Model.ViewModel.GetProperty(propertyInfo.Name)"
                                    autocomplete-filter-param-name="@propertyInfo.Lookup.FilterParamName"
                                    autocomplete-items-property-name="@propertyInfo.Lookup.ResultListPropertyName"
                                    autocomplete-display-property-name="@propertyInfo.Lookup.DisplayPropertyName"
                                    autocomplete-value-property-name="@propertyInfo.Lookup.ValuePropertyName"></abp-select>
                    }
                    else
                    {
                        <abp-input type="@propertyInfo.GetInputType()"
                                   asp-for="ViewModel.ExtraProperties[propertyInfo.Name]"
                                   label="@propertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)"
                                   asp-format="@propertyInfo.GetInputFormatOrNull()"
                                   value="@propertyInfo.GetInputValueOrNull(Model.ViewModel.GetProperty(propertyInfo.Name))" />
                    }
                }
            }
        </form>
    </abp-card-body>
    <abp-card-footer>
        <abp-button button-type="Secondary" type="button" text="@L["SaveAsDraft"].Value" id="button-page-save-draft" />
        <abp-button button-type="Primary" type="button" text="@L["Publish"].Value" id="button-page-publish" />
    </abp-card-footer>
</abp-card>
<input hidden id="GeneratedWidgetText" />